<?php

namespace app\model;

use app\BaseModel;
use think\model\relation\BelongsTo;
use think\model\relation\HasMany;

/**
 * 因子表
 */
class RatingScaleFactorModel extends BaseModel
{
    protected $name = 'rating_scale_factor';

    /**
     * 新增数据验证
     * @return array
     */
    public function addValidate(): array
    {
        return [
            'rating_scale_id|量表id'  => 'require',
            'name|因子名'  => 'require',
        ];
    }

    public function ratingScalePreviousName(): BelongsTo
    {
        return $this->belongsTo(RatingScaleModel::class,'rating_scale_id')->bind([
            'rating_scale_previous_name' => 'previous_name'
        ]);
    }

    /**
     * 管理题目结果因子关系
     * @return HasMany
     */
    public function relatedQuestions(): HasMany
    {
        return $this->hasMany(RatingScaleQuestionRelatedFactorModel::class,'factor_id');
    }

    /**
     * 关联因子等级列表
     * @return HasMany
     */
    public function RatingScaleFactorLevel(): HasMany
    {
        return $this->hasMany(RatingScaleFactorLevelModel::class,'factor_id');
    }



}